<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@page import="org.jeecgframework.web.util.StaticValue" %>
<%@include file="/context/mytags.jsp" %>
<t:base type="jquery,easyui,tools,DatePicker"></t:base>
<div class="easyui-layout" fit="true">
    <div region="center" style="padding:1px;">
        <t:datagrid name="cbsAppKnowledgeList" checkbox="true" fitColumns="false" title="知识库"
                    actionUrl="cbsAppKnowledgeController.do?datagrid" idField="id" fit="true" queryMode="group">
            <t:dgCol title="id" field="id" hidden="true" queryMode="group" width="120"></t:dgCol>
            <t:dgCol title="编号" field="no" query="true" queryMode="single" width="120"></t:dgCol>
            <t:dgCol title="类别" field="knowLedgeType" dictionary="<%=StaticValue.Know_Ledge_TYPE %>" queryMode="single"
                     query="true" width="120"></t:dgCol>
            <t:dgCol title="可见角色" field="roleName" queryMode="single" query="true" width="420"></t:dgCol>
            <t:dgCol title="可见角色id" field="roleid" queryMode="single" query="true" width="420" hidden="true"></t:dgCol>
            <t:dgCol title="机型" field="zyEsItem" queryMode="single" query="true" width="120"></t:dgCol>
            <t:dgCol title="标题" field="title" query="true" queryMode="single" width="120"></t:dgCol>
            <t:dgCol title="操作" field="opt" width="100"></t:dgCol>
            <t:dgDelOpt title="删除" url="cbsAppKnowledgeController.do?doDel&id={id}"/>
            <t:dgToolBar title="录入" icon="icon-add" url="cbsAppKnowledgeController.do?goAdd"
                         funname="add"></t:dgToolBar>
            <t:dgToolBar title="编辑" icon="icon-edit" url="cbsAppKnowledgeController.do?goUpdate"
                         funname="update"></t:dgToolBar>
            <t:dgToolBar title="查看" icon="icon-search" url="cbsAppKnowledgeController.do?goUpdate"
                         funname="detail"></t:dgToolBar>
        </t:datagrid>
    </div>
</div>
<script type="text/javascript">
    $(function () {
        $("div[name='searchColums'] span:nth-child(4)").hide();
        $('#cbsAppKnowledgeList').datagrid({
            idField: 'id',
            title: '知识库',
            url: 'cbsAppKnowledgeController.do?datagrid&field=id,no,knowLedgeType,roleName,zyEsItem,title,',
            fit: true,
            loadMsg: '数据加载中...',
            pageSize: 20,
            pagination: true,
            pageList: [20, 50.0, 100, 2000],
            sortOrder: 'asc',
            rownumbers: true,
            singleSelect: false,
            fitColumns: false,
            showFooter: true,
            nowrap: false,
            frozenColumns: [[{field: 'ck', checkbox: 'true'},]],
            columns: [[{field: 'id', title: 'id', width: 120, hidden: true, sortable: true}, {
                field: 'no',
                title: '编号',
                width: 120,
                sortable: true
            }, {
                field: 'knowLedgeType',
                title: '类别',
                width: 120,
                sortable: true,
                formatter: function (value, rec, index) {
                    var valArray = value.split(",");
                    if (valArray.length > 1) {
                        var checkboxValue = "";
                        for (var k = 0; k < valArray.length; k++) {
                            if (valArray[k] == 'knowLedgeDoc') {
                                checkboxValue = checkboxValue + '技术文档' + ','
                            }
                            if (valArray[k] == 'knowLedgePolicy') {
                                checkboxValue = checkboxValue + '服务政策' + ','
                            }
                            if (valArray[k] == 'knowLedgeNotive') {
                                checkboxValue = checkboxValue + '最新通知' + ','
                            }
                            if (valArray[k] == 'knowLedgeMaintain') {
                                checkboxValue = checkboxValue + '清洁维护' + ','
                            }
                            if (valArray[k] == 'knowLedgeUse') {
                                checkboxValue = checkboxValue + '系统使用' + ','
                            }
                        }
                        return checkboxValue.substring(0, checkboxValue.length - 1);
                    } else {
                        if (value == 'knowLedgeDoc') {
                            return '技术文档'
                        }
                        if (value == 'knowLedgePolicy') {
                            return '服务政策'
                        }
                        if (value == 'knowLedgeNotive') {
                            return '最新通知'
                        }
                        if (value == 'knowLedgeMaintain') {
                            return '清洁维护'
                        }
                        if (value == 'knowLedgeUse') {
                            return '系统使用'
                        } else {
                            return value
                        }
                    }
                }
            }, {field: 'roleName', title: '可见角色', width: 420, sortable: true}, {
                field: 'zyEsItem',
                title: '机型',
                width: 120,
                sortable: true
            }, {field: 'title', title: '标题', width: 120, sortable: true}, {
                field: 'opt',
                title: '操作',
                width: 100,
                formatter: function (value, rec, index) {
                    if (!rec.id) {
                        return '';
                    }
                    var href = '';
                    href += "[<a href='#' onclick=delObj('cbsAppKnowledgeController.do?doDel&id=" + rec.id + "','cbsAppKnowledgeList')>";
                    href += "删除</a>]";
                    return href;
                }
            }]],
            onLoadSuccess: function (data) {
                $("#cbsAppKnowledgeList").datagrid("clearSelections");
            },
            onClickRow: function (rowIndex, rowData) {
                rowid = rowData.id;
                gridname = 'cbsAppKnowledgeList';
            }
        });

        chooseRoleNameForQueryParam("roleName");
    });

    /**
     * 通用 绑定搜索条件 弹出式选择角色项
     */
    function chooseRoleNameForQueryParam() {
        $("#roleName").removeAttr("onkeypress onkeydown").focus(function () {
            $.dialog({
                content: 'url:userController.do?chooseroles',
                zIndex: 21000,
                title: '选择角色',
                lock: true,
                width: '300px',
                height: '400px',
                left: '85%',
                top: '65%',
                opacity: 0.4,
                init: function () {
                    top.myWindow = window;
                },
                ok: function () {
                    var iframe = this.iframe.contentWindow;
                    var selected = iframe.getSelectRows();
                    if (selected == '' || selected == null) {
                        alert("请选择角色");
                        return false;
                    } else {
                        var str = "";
                        var id = "";
                        $.each(selected, function (i, n) {
                            if (i == 0) {
                                str += n.roleName;
                                id += n.id;
                            } else {
                                str += "," + n.roleName;
                                id += "," + n.id;
                            }

                        });
                        $("#roleName").val(str);
                        $("#roleid").val(id);
                        return true;
                    }
                },
                cancelVal: '关闭',
                cancel: function () {
                }
            });
        });
    }

</script>
